package com.yxjx.duoxue.datamodel;

import java.io.Serializable;

import org.json.JSONException;
import org.json.JSONObject;

import com.yxjx.duoxue.utils.UIHelper;

public class DMCommentLevel implements Serializable {

    /**
	 * 
	 */
	private static final long serialVersionUID = 8752719557798729864L;
	private Integer totalLevel = 0;
    private Integer level1 = 0;
    private Integer level2 = 0;
    private Integer level3 = 0;
    private Integer level4 = 0;
    
    public Integer getTotalLevel() {
        return totalLevel;
    }

    public void setTotalLevel(Integer totalLevel) {
        this.totalLevel = totalLevel;
    }

    public Integer getLevel1() {
        return level1;
    }

    public void setLevel1(Integer level1) {
        this.level1 = level1;
    }

    public Integer getLevel2() {
        return level2;
    }

    public void setLevel2(Integer level2) {
        this.level2 = level2;
    }

    public Integer getLevel3() {
        return level3;
    }

    public void setLevel3(Integer level3) {
        this.level3 = level3;
    }

    public Integer getLevel4() {
        return level4;
    }

    public void setLevel4(Integer level4) {
        this.level4 = level4;
    }

    @Override
    public String toString() {
        return "{\"totalLevel\":\"" + totalLevel + "\", \"level1\":\"" + level1 + "\", \"level2\":\"" + level2 + "\", \"level3\":\"" + level3 + "\", \"level4\":\""
                + level4 + "\"}";
    }
    
    /**
     * parse DMCommentLevel object from String.
     * @param str
     * @return
     */
    public static DMCommentLevel from(String str) {
    	if (UIHelper.isEmpty(str)) {
    		return null;
    	}
    	DMCommentLevel commentLevel = null;
    	try {
			JSONObject jo = new JSONObject(str);
			commentLevel =  new DMCommentLevel();
			commentLevel.setLevel1(jo.getInt("totalLevel"));
			commentLevel.setLevel2(jo.getInt("level2"));
			commentLevel.setLevel3(jo.getInt("level3"));
			commentLevel.setLevel4(jo.getInt("level4"));
			commentLevel.setTotalLevel(jo.getInt("totalLevel"));
		} catch (JSONException e) {
			e.printStackTrace();
		}
    	return commentLevel;
    }



}